package day1206zy.day1206zy8;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class demo8 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        ArrayList<String> cats = new ArrayList<>();
        List<String> list = FileUtils.readLines(new File("src\\day1206zy8\\CatData.txt"));
        String str="";
        for (String s : list) {
            String[] sp1 = s.split("'");
            cats.add((sp1[1]));
        }
        Class<?> clazz = Class.forName("day1206zy8.Cat");
        for (int i = 0; i < cats.size(); i++) {
            Method setName = clazz.getDeclaredMethod("setName", String.class);
            Object o = clazz.getDeclaredConstructor().newInstance();
            setName.invoke(o,cats.get(i));
            Method getName = clazz.getDeclaredMethod("getName");
            Object invoke = getName.invoke(o);
            System.out.println(invoke);
        }

    }
}
